package com.shylock.as.api.controller;

import com.shylock.as.manager.intf.AliOssService;
import com.shylock.common.util.RUtils;
import com.shylock.common.vo.R;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
@RequestMapping("/api/oss/")
@Api(value = "实现资源操作",tags = "实现资源操作相关接口")
public class AliOssController {
    @Autowired
    private AliOssService service;

    @PostMapping("uploadHeadImg")
    public R upload(@RequestParam("file") MultipartFile file) throws IOException {
        if(file!=null &&!file.isEmpty()) {
            return service.upload(file.getOriginalFilename(), file.getBytes());
        }else {
            return RUtils.fail("请选择上传的图片");
        }
    }
}
